<template>
	<view>
		<view style="width: 100%;height: 500rpx;border: 0px solid red;background-color: #18B566;border-radius: 20rpx;">
			<image v-if="!wode" style="margin-left: 100rpx;width: 150rpx;height: 150rpx;border-radius: 100rpx;border: 0px solid red;float: left;margin-top: 150rpx;" src="../../static/uview/common/logo.png"></image>
		<view v-if="!wode" style="float: left;margin-top: 200rpx;margin-left: 20rpx;font-size: 35rpx;font-weight: 600;">壹心</view>
		
		
		<view >
			<image style="margin-left: 100rpx;width: 150rpx;height: 150rpx;border-radius: 100rpx;border: 0px solid red;float: left;margin-top: 150rpx;" :src="lisett"></image>
			<view>
			<view style="float: left;margin-top: 200rpx;margin-left: 20rpx;font-size: 35rpx;font-weight: 600;">{{lisettt}}</view>
			</view>
			
		</view>
		
		
	<button v-if="!hasUserInfo" style="margin-left: -360rpx;width: 120rpx;font-size: 25rpx;float: left;margin-top: 280rpx;height: 40rpx;line-height: 40rpx;border-radius: 80rpx;border: 1px solid #E4E7ED;"  @tap="goLogin">登录</button>
	<!-- <button @click="tui()">退出</button> -->
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lisettt:"",
				lisett:"",
				
				hasUserInfo: false,
				wode:false
			}
		},
		onLoad() {
			this.chaxun()
		},
		methods: {
			tui(){
				uni.removeStorageSync("user")
				uni.reLaunch({
					url:"../denglu/denglu"
				})
			},goLogin() {
				var that=this
			    // 获取code 小程序专有，用户登录凭证。
			        uni.login({
			            provider: 'weixin',
			            success(login) {
			                console.log(login);
			            }
			        })
			        // desc: '用于完善会员资料'  必填 声明获取用户个人信息后的用途，后续会展示在弹窗中
			        uni.getUserProfile({
			            desc: '用于完善会员资料',  
			            lang: 'zh_CN',
			            success(user) {
			                console.log(user);
						that.lisettt=user.userInfo.nickName
						that.lisett=user.userInfo.avatarUrl
						if(that.lisettt!=""&&that.lisett!=""){
							that.hasUserInfo = true
							that.wode=true
							that.xinzeng(user)
						}else{
							that.hasUserInfo=false
						}
						
							
			            }
			        })
			},xinzeng(user){
				var that=this
				var par={
					UserName:user.userInfo.nickName,
					Ico:user.userInfo.avatarUrl,
					Position:"J01"
				}
				const db = uniCloud.database();
				db.collection("tblUser")
				.add(par)
				.then(function(par){
					uni.showModal({
						title:"授权成功"
					})
				})
				
			},
			chaxun(){
				var that=this
				var par={
					UserName:uni.getStorageSync("wodeye").nickName,
					Ico:uni.getStorageSync("wodeye").avatarUrl
				}
				const db = uniCloud.database();
				db.collection("tblUser")
				.where(par)
				.get()
				.then(function(W){
					if(uni.getStorageSync("wodeye")!=""){
						that.lisettt=uni.getStorageSync("wodeye").nickName
						that.lisett=uni.getStorageSync("wodeye").avatarUrl
						that.hasUserInfo = true
						that.wode=true
					}else{
									uni.showModal({
										title:"不好意思没有查到您的相关信息"
									})
								}
					
				})
			}
		}
	}
</script>

<style>

</style>
